﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Windows.Forms;

namespace PoolSide
{
    static class Program
    {
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new frmMain());
        }

        #region Program Private member variables
        private static string urlAcct = "https://mining.bitcoin.cz/accounts/profile/json/";
        private static string urlPool = "https://mining.bitcoin.cz/stats/json/";
        private static bool IsDev = false;

        private static List<string> _Currencies;
        private static Dictionary<string, List<string>> _CurrExchanges;
        private static Dictionary<string, string> _Exchanges;
        private static char[] sepCSV
        {
            get
            {
                char[] sep = new char[1];
                sep[0] = ',';
                return sep;
            }
        }
        #endregion

        #region Program Properties
        // Account-based:
        public static string Username { get; set; }
        public static decimal SendThreshold { get; set; }
        public static decimal ConfirmedReward { get; set; }
        public static decimal UnconfirmedReward { get; set; }
        public static decimal Hashrate { get; set; }
        public static string Wallet { get; set; }
        
        // Round-based:
        public static string RoundDuration { get; set; }
        public static string PoolPerformance { get; set; }
        public static string CurrentSharesCDF { get; set; }
        public static DateTime CurrentRoundStarted { get; set; }
        public static string CurrentRoundScore { get; set; }
        public static string CurrentRoundShares { get; set; }
        public static string Luck1 { get; set; }
        public static string Luck7 { get; set; }
        public static string Luck30 { get; set; }

        // Exchange-based:
        public static DateTime LastDataPullTime { get; set; }
        public static List<string> Currencies
        {
            get
            {
                return _Currencies; 
            }
        }
        public static Dictionary<string, List<string>> CurrencyExchanges
        {
            get
            {
                if (_CurrExchanges == null)
                {
                    // reset member vars
                    _Currencies = new List<string>();
                    _CurrExchanges = new Dictionary<string, List<string>>();
                    
                    // some working variables:
                    string[] part = null;
                    List<string> exch = null;

                    // loop through CurrExchanges
                    foreach (string str in Properties.Settings.Default.CurrExchanges)
                    {
                        part = str.Split(sepCSV); // Split into the array (comma-delimites in the properties file)
                        _Currencies.Add(part[0]); // add string[0] to the list of currencies
                        exch = new List<string>();  // reset the list of available exchanges for each currency
                        
                        // add the exchanges for each currency type into the 'exch' list:
                        for (int i = 1; i <= part.Length - 1; i++)
                        {
                            exch.Add(part[i]);
                        }

                        // finally add to the dictionary object
                        _CurrExchanges.Add(part[0], exch);
                    }
                }
                return _CurrExchanges;
            }
        }
        public static string LastMarketJsonString { get; set; }
        public static string LastMarketPassword { get; set; }

        // Other
        public static string ApiKey
        {
            get 
            {
                string key = Properties.Settings.Default.ApiKey.Trim();
                if (key == "\r\n") key = "";
                return key;
            }
        }
        public static bool IsAutoRefresh
        {
            get { return Properties.Settings.Default.IsAutoRefresh; }
        }
        public static int RefreshInterval
        {
            get { return Properties.Settings.Default.RefreshInterval; }
        }
          
        #endregion

        #region Program Methods
        public static string GetUserAccountJson()
        {
            string jsonAcct = "";
            var reqAcct = WebRequest.Create(string.Concat(urlAcct, Program.ApiKey));
            using (var rAcct = (HttpWebResponse)reqAcct.GetResponse())
            {
                using (var rdrAcct = new StreamReader(rAcct.GetResponseStream()))
                {
                    jsonAcct = rdrAcct.ReadToEnd().Replace("\"", "'");
                }
            }
            return jsonAcct;
        }
        public static string GetPoolRoundJson()
        {
            string jsonPool = "";
            var request = WebRequest.Create(string.Concat(urlPool, Program.ApiKey));
            using (var resp = (HttpWebResponse)request.GetResponse())
            {
                using (var reader = new StreamReader(resp.GetResponseStream()))
                {
                    jsonPool = reader.ReadToEnd().Replace("\"", "'");
                }
            }
            return jsonPool;
        }
        public static string GetMarketsAPIJson()
        {
            if (IsDev)
                return "[{'volume': 5.961100000000, 'latest_trade': 1379600172, 'bid': 1051.650000000000, 'high': 1300.200000000000, 'currency': 'ARS', 'currency_volume': 6740.612769000000, 'ask': 784.740000000000, 'close': 1109.470000000000, 'avg': 1130.766598278841153478384862, 'symbol': 'localbtcARS', 'low': 963.680000000000}, {'volume': 0, 'latest_trade': 1349296271, 'bid': null, 'high': null, 'currency': 'AUD', 'currency_volume': 0, 'ask': null, 'close': 14.000000000000, 'avg': null, 'symbol': 'bitmarketAUD', 'low': null}, {'volume': 0, 'latest_trade': 1353317656, 'bid': null, 'high': null, 'currency': 'AUD', 'currency_volume': 0, 'ask': null, 'close': 22.000000000000, 'avg': null, 'symbol': 'cryptoxAUD', 'low': null}, {'volume': 192.392300000000, 'latest_trade': 1379613708, 'bid': 173.120000000000, 'high': 154.780000000000, 'currency': 'AUD', 'currency_volume': 26745.249908000000, 'ask': 134.600000000000, 'close': 145.240000000000, 'avg': 139.0141388610666851012228660, 'symbol': 'localbtcAUD', 'low': 125.000000000000}, {'volume': 275.792780330000, 'latest_trade': 1379615485, 'bid': 142.885270000000, 'high': 150.508290000000, 'currency': 'AUD', 'currency_volume': 40535.637675200892, 'ask': 145.999900000000, 'close': 145.838890000000, 'avg': 146.9786033800375516885815790, 'symbol': 'mtgoxAUD', 'low': 142.165890000000}, {'volume': 0, 'latest_trade': 1318748737, 'bid': null, 'high': null, 'currency': 'AUD', 'currency_volume': 0, 'ask': null, 'close': 4.250000000000, 'avg': null, 'symbol': 'ruxumAUD', 'low': null}, {'volume': 0, 'latest_trade': 1329028868, 'bid': null, 'high': null, 'currency': 'AUD', 'currency_volume': 0, 'ask': null, 'close': 5.899978679200, 'avg': null, 'symbol': 'thAUD', 'low': null}, {'volume': 0, 'latest_trade': 1378162807, 'bid': 129.000000000000, 'high': null, 'currency': 'AUD', 'currency_volume': 0, 'ask': 130.000000000000, 'close': 130.000000000000, 'avg': null, 'symbol': 'wbxAUD', 'low': null}, {'volume': 0, 'latest_trade': 1375713657, 'bid': 100.000000000000, 'high': null, 'currency': 'AUD', 'currency_volume': 0, 'ask': 119.000000000000, 'close': 117.500000000000, 'avg': null, 'symbol': 'weexAUD', 'low': null}, {'volume': 0, 'latest_trade': 1320965054, 'bid': null, 'high': null, 'currency': 'BRL', 'currency_volume': 0, 'ask': null, 'close': 18.000000000000, 'avg': null, 'symbol': 'bbmBRL', 'low': null}, {'volume': 2.538500000000, 'latest_trade': 1379543024, 'bid': 291.420000000000, 'high': 326.400000000000, 'currency': 'BRL', 'currency_volume': 816.701200000000, 'ask': 301.230000000000, 'close': 321.160000000000, 'avg': 321.7259011227102619657277920, 'symbol': 'localbtcBRL', 'low': 319.000000000000}, {'volume': 63.278610760000, 'latest_trade': 1379616273, 'bid': 305.000000000000, 'high': 318.900000000000, 'currency': 'BRL', 'currency_volume': 19899.363345852600, 'ask': 314.890000000000, 'close': 315.000000000000, 'avg': 314.4721906320909248735219863, 'symbol': 'mrcdBRL', 'low': 308.679000000000}, {'volume': 44.750000000000, 'latest_trade': 1379616201, 'bid': 138.240000000000, 'high': 151.580000000000, 'currency': 'CAD', 'currency_volume': 5882.897222000000, 'ask': 133.420000000000, 'close': 145.000000000000, 'avg': 131.4613904357541899441340782, 'symbol': 'localbtcCAD', 'low': 114.000000000000}, {'volume': 0, 'latest_trade': 1370836515, 'bid': 95.200000000000, 'high': null, 'currency': 'CAD', 'currency_volume': 0, 'ask': 104.900000000000, 'close': 104.970000000000, 'avg': null, 'symbol': 'lybitCAD', 'low': null}, {'volume': 123.812293840000, 'latest_trade': 1379616083, 'bid': 135.990000000000, 'high': 143.990000000000, 'currency': 'CAD', 'currency_volume': 17383.538182815505, 'ask': 141.989980000000, 'close': 136.105420000000, 'avg': 140.4023594400074883549221545, 'symbol': 'mtgoxCAD', 'low': 136.105420000000}, {'volume': 537.400600000000, 'latest_trade': 1379616981, 'bid': 125.000100000000, 'high': 128.000000000000, 'currency': 'CAD', 'currency_volume': 67969.309235985000, 'ask': 125.979800000000, 'close': 125.979800000000, 'avg': 126.4779184019984346872705390, 'symbol': 'virtexCAD', 'low': 124.500000000000}, {'volume': 0, 'latest_trade': 1375169750, 'bid': null, 'high': null, 'currency': 'CAD', 'currency_volume': 0, 'ask': 88.000000000000, 'close': 88.000000000000, 'avg': null, 'symbol': 'weexCAD', 'low': null}, {'volume': 7.001400000000, 'latest_trade': 1379575595, 'bid': 117.840000000000, 'high': 130.330000000000, 'currency': 'CHF', 'currency_volume': 895.566526000000, 'ask': 121.810000000000, 'close': 126.110000000000, 'avg': 127.9124926443282772017025166, 'symbol': 'localbtcCHF', 'low': 126.090000000000}, {'volume': 7.947252800000, 'latest_trade': 1379612918, 'bid': 125.285080000000, 'high': 130.827900000000, 'currency': 'CHF', 'currency_volume': 1036.414923632000, 'ask': 128.005350000000, 'close': 125.285080000000, 'avg': 130.4117221025106940098847743, 'symbol': 'mtgoxCHF', 'low': 125.000000000000}, {'volume': 0, 'latest_trade': 1318992534, 'bid': null, 'high': null, 'currency': 'CHF', 'currency_volume': 0, 'ask': 3.900000000000, 'close': 3.000000000000, 'avg': null, 'symbol': 'ruxumCHF', 'low': null}, {'volume': 0, 'latest_trade': 1329168604, 'bid': null, 'high': null, 'currency': 'CLP', 'currency_volume': 0, 'ask': null, 'close': 3050.000000000000, 'avg': null, 'symbol': 'thCLP', 'low': null}, {'volume': 603.816000000000, 'latest_trade': 1379588287, 'bid': 754.020000000000, 'high': 760.000000000000, 'currency': 'CNY', 'currency_volume': 456755.905180000000, 'ask': 757.990000000000, 'close': 754.010000000000, 'avg': 756.4488274242484465466300992, 'symbol': 'btcnCNY', 'low': 751.610000000000}, {'volume': 0.712997230000, 'latest_trade': 1379611031, 'bid': 813.109440000000, 'high': 864.333950000000, 'currency': 'CNY', 'currency_volume': 603.081218368415, 'ask': 845.745920000000, 'close': 820.000000000000, 'avg': 845.8394969759069049959703210, 'symbol': 'mtgoxCNY', 'low': 820.000000000000}, {'volume': 0, 'latest_trade': 1369383872, 'bid': 743.200000000000, 'high': null, 'currency': 'CNY', 'currency_volume': 0, 'ask': 744.150000000000, 'close': 751.800000000000, 'avg': null, 'symbol': 'rmbtbCNY', 'low': null}, {'volume': 16.215512900000, 'latest_trade': 1379615631, 'bid': 2424.000000000000, 'high': 2560.000000000000, 'currency': 'CZK', 'currency_volume': 40159.471992000000, 'ask': 2499.000000000000, 'close': 2450.000000000000, 'avg': 2476.608186226412856789747304, 'symbol': 'bitcashCZK', 'low': 2450.000000000000}, {'volume': 3.500000000000, 'latest_trade': 1379579439, 'bid': 2325.860000000000, 'high': 2579.470000000000, 'currency': 'CZK', 'currency_volume': 9028.145000000000, 'ask': 2491.990000000000, 'close': 2579.470000000000, 'avg': 2579.47, 'symbol': 'localbtcCZK', 'low': 2579.470000000000}, {'volume': 0, 'latest_trade': 1378934854, 'bid': 694.530000000000, 'high': null, 'currency': 'DKK', 'currency_volume': 0, 'ask': 720.040000000000, 'close': 739.070000000000, 'avg': null, 'symbol': 'localbtcDKK', 'low': null}, {'volume': 1.200000000000, 'latest_trade': 1379535257, 'bid': 745.381140000000, 'high': 794.937520000000, 'currency': 'DKK', 'currency_volume': 953.925024000000, 'ask': 771.747030000000, 'close': 794.937520000000, 'avg': 794.93752, 'symbol': 'mtgoxDKK', 'low': 794.937520000000}, {'volume': 0, 'latest_trade': 1321512379, 'bid': null, 'high': null, 'currency': 'EUR', 'currency_volume': 0, 'ask': null, 'close': 1.710000000000, 'avg': null, 'symbol': 'aqoinEUR', 'low': null}, {'volume': 0, 'latest_trade': 1317822453, 'bid': null, 'high': null, 'currency': 'EUR', 'currency_volume': 0, 'ask': null, 'close': 3.300000000000, 'avg': null, 'symbol': 'b7EUR', 'low': null}, {'volume': 0, 'latest_trade': 1366826331, 'bid': null, 'high': null, 'currency': 'EUR', 'currency_volume': 0, 'ask': null, 'close': 118.000000000000, 'avg': null, 'symbol': 'bcEUR', 'low': null}, {'volume': 101.017185540000, 'latest_trade': 1379616169, 'bid': 92.600000000000, 'high': 93.800000000000, 'currency': 'EUR', 'currency_volume': 9410.970620216000, 'ask': 93.500000000000, 'close': 92.550000000000, 'avg': 93.16207504602785630133088343, 'symbol': 'bitcurexEUR', 'low': 92.550000000000}, {'volume': 0, 'latest_trade': 1361021172, 'bid': null, 'high': null, 'currency': 'EUR', 'currency_volume': 0, 'ask': null, 'close': 19.990000000000, 'avg': null, 'symbol': 'bitmarketEUR', 'low': null}, {'volume': 0, 'latest_trade': 1365850828, 'bid': null, 'high': null, 'currency': 'EUR', 'currency_volume': 0, 'ask': null, 'close': 76.012250000000, 'avg': null, 'symbol': 'btc24EUR', 'low': null}, {'volume': 819.583314570000, 'latest_trade': 1379617039, 'bid': 94.000000000000, 'high': 115.000000000000, 'currency': 'EUR', 'currency_volume': 78332.887640308400, 'ask': 94.400000000000, 'close': 94.200000000000, 'avg': 95.57647922762591386804786645, 'symbol': 'btcdeEUR', 'low': 92.220000000000}, {'volume': 127.155254580000, 'latest_trade': 1379617297, 'bid': 96.750000000000, 'high': 100.000000000000, 'currency': 'EUR', 'currency_volume': 12491.197900671200, 'ask': 97.480000000000, 'close': 97.480000000000, 'avg': 98.23579797728560373269632913, 'symbol': 'btceEUR', 'low': 96.750000000000}, {'volume': 0, 'latest_trade': 1305076646, 'bid': null, 'high': null, 'currency': 'EUR', 'currency_volume': 0, 'ask': null, 'close': 3.900000000000, 'avg': null, 'symbol': 'btcexEUR', 'low': null}, {'volume': 0.103181770000, 'latest_trade': 1379603073, 'bid': 95.000000000000, 'high': 96.000000000000, 'currency': 'EUR', 'currency_volume': 9.825100940000, 'ask': 96.000000000000, 'close': 95.000000000000, 'avg': 95.22128705487413135091596122, 'symbol': 'crytrEUR', 'low': 95.000000000000}, {'volume': 75.628623440000, 'latest_trade': 1379611494, 'bid': 91.550000000000, 'high': 95.900000000000, 'currency': 'EUR', 'currency_volume': 7143.397212364400, 'ask': 94.990000000000, 'close': 94.500000000000, 'avg': 94.45361937642058449715450751, 'symbol': 'fbtcEUR', 'low': 91.530000000000}, {'volume': 0, 'latest_trade': 1317816883, 'bid': null, 'high': null, 'currency': 'EUR', 'currency_volume': 0, 'ask': null, 'close': 4.000000000000, 'avg': null, 'symbol': 'globalEUR', 'low': null}, {'volume': 0, 'latest_trade': 1348229048, 'bid': null, 'high': null, 'currency': 'EUR', 'currency_volume': 0, 'ask': null, 'close': 7.711538461540, 'avg': null, 'symbol': 'imcexEUR', 'low': null}, {'volume': 56.960100000000, 'latest_trade': 1379611608, 'bid': 97.121000000000, 'high': 98.890000000000, 'currency': 'EUR', 'currency_volume': 5592.541392610000, 'ask': 98.885210000000, 'close': 98.888900000000, 'avg': 98.18348971666131204123588266, 'symbol': 'intrsngEUR', 'low': 97.000000000000}, {'volume': 0, 'latest_trade': 1379502356, 'bid': 86.681000000000, 'high': null, 'currency': 'EUR', 'currency_volume': 0, 'ask': 99.015000000000, 'close': 99.713000000000, 'avg': null, 'symbol': 'justEUR', 'low': null}, {'volume': 195.403200000000, 'latest_trade': 1379615136, 'bid': 114.550000000000, 'high': 114.630000000000, 'currency': 'EUR', 'currency_volume': 18614.611228000000, 'ask': 90.840000000000, 'close': 92.330000000000, 'avg': 95.26257107355457843065006100, 'symbol': 'localbtcEUR', 'low': 85.340000000000}, {'volume': 2904.492554780000, 'latest_trade': 1379617292, 'bid': 100.993000000000, 'high': 105.000000000000, 'currency': 'EUR', 'currency_volume': 296288.559119087601, 'ask': 101.000000000000, 'close': 101.000000000000, 'avg': 102.0104384951779976137481129, 'symbol': 'mtgoxEUR', 'low': 97.550000000000}, {'volume': 0, 'latest_trade': 1379371430, 'bid': 80.000000000000, 'high': null, 'currency': 'EUR', 'currency_volume': 0, 'ask': 99.900000000000, 'close': 78.000000000000, 'avg': null, 'symbol': 'rippleEUR', 'low': null}, {'volume': 44.100000000000, 'latest_trade': 1379616130, 'bid': 94.250000000000, 'high': 95.900000000000, 'currency': 'EUR', 'currency_volume': 4189.075900000000, 'ask': 95.250000000000, 'close': 95.000000000000, 'avg': 94.99038321995464852607709751, 'symbol': 'rockEUR', 'low': 93.760000000000}, {'volume': 0, 'latest_trade': 1338569911, 'bid': 4.407990000000, 'high': null, 'currency': 'EUR', 'currency_volume': 0, 'ask': null, 'close': 5.000000000000, 'avg': null, 'symbol': 'ruxumEUR', 'low': null}, {'volume': 0, 'latest_trade': 1329146896, 'bid': null, 'high': null, 'currency': 'EUR', 'currency_volume': 0, 'ask': null, 'close': 4.160000000000, 'avg': null, 'symbol': 'thEUR', 'low': null}, {'volume': 0, 'latest_trade': 1375795428, 'bid': 82.400000000000, 'high': null, 'currency': 'EUR', 'currency_volume': 0, 'ask': 87.940000000000, 'close': 87.940000000000, 'avg': null, 'symbol': 'vcxEUR', 'low': null}, {'volume': 0, 'latest_trade': 1312214090, 'bid': null, 'high': null, 'currency': 'GAU', 'currency_volume': 0, 'ask': null, 'close': 0.267000000000, 'avg': null, 'symbol': 'bcmBMGAU', 'low': null}, {'volume': 0, 'latest_trade': 1313452498, 'bid': null, 'high': null, 'currency': 'GAU', 'currency_volume': 0, 'ask': null, 'close': 0.200000000000, 'avg': null, 'symbol': 'bcmPXGAU', 'low': null}, {'volume': 0, 'latest_trade': 1366825383, 'bid': null, 'high': null, 'currency': 'GBP', 'currency_volume': 0, 'ask': null, 'close': 99.707996640000, 'avg': null, 'symbol': 'bcGBP', 'low': null}, {'volume': 0, 'latest_trade': 1314988355, 'bid': null, 'high': null, 'currency': 'GBP', 'currency_volume': 0, 'ask': null, 'close': 5.500000000000, 'avg': null, 'symbol': 'bitmarketGBP', 'low': null}, {'volume': 0, 'latest_trade': 1316391901, 'bid': null, 'high': null, 'currency': 'GBP', 'currency_volume': 0, 'ask': null, 'close': 3.662700000000, 'avg': null, 'symbol': 'britcoinGBP', 'low': null}, {'volume': 0, 'latest_trade': 1320274888, 'bid': null, 'high': null, 'currency': 'GBP', 'currency_volume': 0, 'ask': null, 'close': 2.990000000000, 'avg': null, 'symbol': 'globalGBP', 'low': null}, {'volume': 0, 'latest_trade': 1378921125, 'bid': 67.591870000000, 'high': null, 'currency': 'GBP', 'currency_volume': 0, 'ask': 68.000000000000, 'close': 68.000000000000, 'avg': null, 'symbol': 'intrsngGBP', 'low': null}, {'volume': 0, 'latest_trade': 1365676967, 'bid': 96.610000000000, 'high': null, 'currency': 'GBP', 'currency_volume': 0, 'ask': 78.220000000000, 'close': 87.950000000000, 'avg': null, 'symbol': 'localbtcGBP', 'low': null}, {'volume': 264.656818050000, 'latest_trade': 1379616083, 'bid': 84.112590000000, 'high': 89.669550000000, 'currency': 'GBP', 'currency_volume': 22826.400751001912, 'ask': 85.169150000000, 'close': 84.726660000000, 'avg': 86.24905611420696214329022838, 'symbol': 'mtgoxGBP', 'low': 83.699060000000}, {'volume': 0, 'latest_trade': 1318792662, 'bid': null, 'high': null, 'currency': 'GBP', 'currency_volume': 0, 'ask': null, 'close': 2.500000000000, 'avg': null, 'symbol': 'ruxumGBP', 'low': null}, {'volume': 0, 'latest_trade': 1373462347, 'bid': 550.000000000000, 'high': null, 'currency': 'HKD', 'currency_volume': 0, 'ask': 620.000000000000, 'close': 572.000000000000, 'avg': null, 'symbol': 'btchkexHKD', 'low': null}, {'volume': 2.099500000000, 'latest_trade': 1379593696, 'bid': 970.600000000000, 'high': 1091.390000000000, 'currency': 'HKD', 'currency_volume': 2283.353305000000, 'ask': 970.600000000000, 'close': 1083.370000000000, 'avg': 1087.570042867349368897356513, 'symbol': 'localbtcHKD', 'low': 1083.370000000000}, {'volume': 4.024000000000, 'latest_trade': 1379611031, 'bid': 1030.427730000000, 'high': 1070.000000000000, 'currency': 'HKD', 'currency_volume': 4245.320000000000, 'ask': 1071.333360000000, 'close': 1040.000000000000, 'avg': 1055, 'symbol': 'mtgoxHKD', 'low': 1040.000000000000}, {'volume': 0, 'latest_trade': 1318797312, 'bid': 6.120000000000, 'high': null, 'currency': 'HKD', 'currency_volume': 0, 'ask': null, 'close': 29.000000000000, 'avg': null, 'symbol': 'ruxumHKD', 'low': null}, {'volume': 0, 'latest_trade': 1319836324, 'bid': 79.000000000000, 'high': null, 'currency': 'HUF', 'currency_volume': 0, 'ask': null, 'close': 79.000000000000, 'avg': null, 'symbol': 'ruxumHUF', 'low': null}, {'volume': 3.000000000000, 'latest_trade': 1379605628, 'bid': 471.000000000000, 'high': 475.000000000000, 'currency': 'ILS', 'currency_volume': 1416.500000000000, 'ask': 480.000000000000, 'close': 475.000000000000, 'avg': 472.1666666666666666666666667, 'symbol': 'bit2cILS', 'low': 470.000000000000}, {'volume': 0, 'latest_trade': 1372343375, 'bid': 580.000000000000, 'high': null, 'currency': 'ILS', 'currency_volume': 0, 'ask': 472.870000000000, 'close': 404.260000000000, 'avg': null, 'symbol': 'localbtcILS', 'low': null}, {'volume': 2.532500000000, 'latest_trade': 1379582381, 'bid': 7189.710000000000, 'high': 8831.990000000000, 'currency': 'INR', 'currency_volume': 22247.585400000000, 'ask': 8117.420000000000, 'close': 8831.990000000000, 'avg': 8784.831352418558736426456071, 'symbol': 'localbtcINR', 'low': 8716.320000000000}, {'volume': 0, 'latest_trade': 1327901200, 'bid': null, 'high': null, 'currency': 'INR', 'currency_volume': 0, 'ask': null, 'close': 318.000000000000, 'avg': null, 'symbol': 'thINR', 'low': null}, {'volume': 0, 'latest_trade': 1299369401, 'bid': null, 'high': null, 'currency': 'JPY', 'currency_volume': 0, 'ask': null, 'close': 1.000000000000, 'avg': null, 'symbol': 'btcexJPY', 'low': null}, {'volume': 5729.847537810000, 'latest_trade': 1379611608, 'bid': 13105.000000000000, 'high': 13798.000000000000, 'currency': 'JPY', 'currency_volume': 75561824.278922874570, 'ask': 13514.998000000000, 'close': 13320.270000000000, 'avg': 13187.40573467392696611538464, 'symbol': 'mtgoxJPY', 'low': 12960.412000000000}, {'volume': 0, 'latest_trade': 1319028730, 'bid': 210.000000000000, 'high': null, 'currency': 'JPY', 'currency_volume': 0, 'ask': null, 'close': 210.000000000000, 'avg': null, 'symbol': 'ruxumJPY', 'low': null}, {'volume': 0.083060000000, 'latest_trade': 1379602924, 'bid': 47.955000000000, 'high': 55.951000000000, 'currency': 'LTC', 'currency_volume': 4.596137060000, 'ask': 54.808000000000, 'close': 55.951000000000, 'avg': 55.33514399229472670358776788, 'symbol': 'justLTC', 'low': 53.245000000000}, {'volume': 1.566400000000, 'latest_trade': 1379615929, 'bid': 1728.030000000000, 'high': 1783.540000000000, 'currency': 'MXN', 'currency_volume': 2515.854056000000, 'ask': 1653.200000000000, 'close': 1560.500000000000, 'avg': 1606.137676200204290091930541, 'symbol': 'localbtcMXN', 'low': 1533.240000000000}, {'volume': 4.349070000000, 'latest_trade': 1379615801, 'bid': 752.001000000000, 'high': 829.990000000000, 'currency': 'NOK', 'currency_volume': 3563.276266800000, 'ask': 771.107000000000, 'close': 764.590000000000, 'avg': 819.3191341597169049934813650, 'symbol': 'justNOK', 'low': 764.590000000000}, {'volume': 27.916300000000, 'latest_trade': 1379608206, 'bid': 732.720000000000, 'high': 861.410000000000, 'currency': 'NOK', 'currency_volume': 21951.185623000000, 'ask': 797.690000000000, 'close': 836.170000000000, 'avg': 786.3214545982096481267216644, 'symbol': 'localbtcNOK', 'low': 704.480000000000}, {'volume': 34.498990000000, 'latest_trade': 1379591759, 'bid': 160.000000000000, 'high': 170.000000000000, 'currency': 'NZD', 'currency_volume': 5735.408573000000, 'ask': 169.490000000000, 'close': 160.000000000000, 'avg': 166.2485937414399667932307583, 'symbol': 'bitnzNZD', 'low': 160.000000000000}, {'volume': 2.054300000000, 'latest_trade': 1379553805, 'bid': 181.000000000000, 'high': 190.230000000000, 'currency': 'NZD', 'currency_volume': 371.757163000000, 'ask': 163.150000000000, 'close': 190.230000000000, 'avg': 180.9653716594460400136299469, 'symbol': 'localbtcNZD', 'low': 178.000000000000}, {'volume': 0.720800000000, 'latest_trade': 1379544245, 'bid': 160.489010000000, 'high': 173.418570000000, 'currency': 'NZD', 'currency_volume': 125.000105256000, 'ask': 168.072990000000, 'close': 173.418570000000, 'avg': 173.41857, 'symbol': 'mtgoxNZD', 'low': 173.418570000000}, {'volume': 0, 'latest_trade': 1319837979, 'bid': null, 'high': null, 'currency': 'PLN', 'currency_volume': 0, 'ask': null, 'close': 10.000000000000, 'avg': null, 'symbol': 'bitchangePLN', 'low': null}, {'volume': 755.044359230000, 'latest_trade': 1379617045, 'bid': 387.000000000000, 'high': 397.790000000000, 'currency': 'PLN', 'currency_volume': 295925.499158470600, 'ask': 389.900000000000, 'close': 386.500000000000, 'avg': 391.9312760117268904955858563, 'symbol': 'bitcurexPLN', 'low': 385.500000000000}, {'volume': 0, 'latest_trade': 1361000593, 'bid': null, 'high': null, 'currency': 'PLN', 'currency_volume': 0, 'ask': null, 'close': 80.000000000000, 'avg': null, 'symbol': 'bitmarketPLN', 'low': null}, {'volume': 0, 'latest_trade': 1313056551, 'bid': null, 'high': null, 'currency': 'PLN', 'currency_volume': 0, 'ask': null, 'close': 29.200000000000, 'avg': null, 'symbol': 'bitomatPLN', 'low': null}, {'volume': 0, 'latest_trade': 1315073674, 'bid': null, 'high': null, 'currency': 'PLN', 'currency_volume': 0, 'ask': null, 'close': 25.000000000000, 'avg': null, 'symbol': 'freshPLN', 'low': null}, {'volume': 0, 'latest_trade': 1325440070, 'bid': null, 'high': null, 'currency': 'PLN', 'currency_volume': 0, 'ask': null, 'close': 15.820000000000, 'avg': null, 'symbol': 'globalPLN', 'low': null}, {'volume': 0, 'latest_trade': 1371620088, 'bid': 0.215640000000, 'high': null, 'currency': 'PLN', 'currency_volume': 0, 'ask': null, 'close': 335.000000000000, 'avg': null, 'symbol': 'intrsngPLN', 'low': null}, {'volume': 0, 'latest_trade': 1379410913, 'bid': 419.010000000000, 'high': null, 'currency': 'PLN', 'currency_volume': 0, 'ask': 405.500000000000, 'close': 418.810000000000, 'avg': null, 'symbol': 'localbtcPLN', 'low': null}, {'volume': 65.217247620000, 'latest_trade': 1379614314, 'bid': 418.247680000000, 'high': 440.000000000000, 'currency': 'PLN', 'currency_volume': 28002.675096367205, 'ask': 429.980000000000, 'close': 429.979960000000, 'avg': 429.3752974601108288844404317, 'symbol': 'mtgoxPLN', 'low': 414.096360000000}, {'volume': 0, 'latest_trade': 1318577499, 'bid': null, 'high': null, 'currency': 'PLN', 'currency_volume': 0, 'ask': null, 'close': 13.500000000000, 'avg': null, 'symbol': 'ruxumPLN', 'low': null}, {'volume': 0, 'latest_trade': 1319445325, 'bid': null, 'high': null, 'currency': 'RUB', 'currency_volume': 0, 'ask': null, 'close': 300.000000000000, 'avg': null, 'symbol': 'bitmarketRUB', 'low': null}, {'volume': 367.538690900000, 'latest_trade': 1379617029, 'bid': 4010.000000000000, 'high': 4144.990000000000, 'currency': 'RUB', 'currency_volume': 1497367.018558525800, 'ask': 4036.998300000000, 'close': 4037.110000000000, 'avg': 4074.039157324880704144663971, 'symbol': 'btceRUR', 'low': 4000.000000000000}, {'volume': 0, 'latest_trade': 1305230002, 'bid': null, 'high': null, 'currency': 'RUB', 'currency_volume': 0, 'ask': null, 'close': 199.000000000000, 'avg': null, 'symbol': 'btcexRUB', 'low': null}, {'volume': 0, 'latest_trade': 1306059105, 'bid': null, 'high': null, 'currency': 'RUB', 'currency_volume': 0, 'ask': null, 'close': 155.000000000000, 'avg': null, 'symbol': 'btcexWMR', 'low': null}, {'volume': 0, 'latest_trade': 1305229968, 'bid': null, 'high': null, 'currency': 'RUB', 'currency_volume': 0, 'ask': null, 'close': 132.000100000000, 'avg': null, 'symbol': 'btcexYAD', 'low': null}, {'volume': 0, 'latest_trade': 1379510456, 'bid': 4092.960000000000, 'high': null, 'currency': 'RUB', 'currency_volume': 0, 'ask': 4146.990000000000, 'close': 4159.480000000000, 'avg': null, 'symbol': 'localbtcRUB', 'low': null}, {'volume': 0.298400000000, 'latest_trade': 1379587359, 'bid': 4262.513780000000, 'high': 4376.872040000000, 'currency': 'RUB', 'currency_volume': 1306.058616736000, 'ask': 4463.940720000000, 'close': 4376.872040000000, 'avg': 4376.87204, 'symbol': 'mtgoxRUB', 'low': 4376.872040000000}, {'volume': 0, 'latest_trade': 1319202603, 'bid': null, 'high': null, 'currency': 'RUB', 'currency_volume': 0, 'ask': 195.000000000000, 'close': 195.000000000000, 'avg': null, 'symbol': 'ruxumRUB', 'low': null}, {'volume': 7.785731000000, 'latest_trade': 1379588761, 'bid': 804.000000000000, 'high': 865.000000000000, 'currency': 'SEK', 'currency_volume': 6685.366698000000, 'ask': 845.220000000000, 'close': 865.000000000000, 'avg': 858.6691086553080243846082019, 'symbol': 'fybseSEK', 'low': 858.000000000000}, {'volume': 207.198520580000, 'latest_trade': 1379616943, 'bid': 833.250000000000, 'high': 860.000000000000, 'currency': 'SEK', 'currency_volume': 174711.085897143331, 'ask': 839.999500000000, 'close': 839.999500000000, 'avg': 843.2062420527121072555295173, 'symbol': 'kptnSEK', 'low': 806.850000000000}, {'volume': 3.587500000000, 'latest_trade': 1379595021, 'bid': 984.670000000000, 'high': 895.280000000000, 'currency': 'SEK', 'currency_volume': 3183.621110000000, 'ask': 856.240000000000, 'close': 883.560000000000, 'avg': 887.4205184668989547038327526, 'symbol': 'localbtcSEK', 'low': 883.560000000000}, {'volume': 8.874939560000, 'latest_trade': 1379610945, 'bid': 870.073000000000, 'high': 900.000000000000, 'currency': 'SEK', 'currency_volume': 7911.299224178640, 'ask': 892.654000000000, 'close': 876.637000000000, 'avg': 891.4200677867647360068331553, 'symbol': 'mtgoxSEK', 'low': 876.637000000000}, {'volume': 0, 'latest_trade': 1319028697, 'bid': null, 'high': null, 'currency': 'SEK', 'currency_volume': 0, 'ask': 35.000000000000, 'close': 20.000000000000, 'avg': null, 'symbol': 'ruxumSEK', 'low': null}, {'volume': 4.609041820000, 'latest_trade': 1379613739, 'bid': 155.600000000000, 'high': 167.830000000000, 'currency': 'SGD', 'currency_volume': 759.086479834700, 'ask': 163.950000000000, 'close': 163.950000000000, 'avg': 164.6950731800259516846822622, 'symbol': 'fybsgSGD', 'low': 159.000000000000}, {'volume': 0, 'latest_trade': 1378034398, 'bid': 160.160000000000, 'high': null, 'currency': 'SGD', 'currency_volume': 0, 'ask': 155.000000000000, 'close': 217.450000000000, 'avg': null, 'symbol': 'localbtcSGD', 'low': null}, {'volume': 0, 'latest_trade': 1379493502, 'bid': 168.581100000000, 'high': null, 'currency': 'SGD', 'currency_volume': 0, 'ask': 173.898940000000, 'close': 172.086510000000, 'avg': null, 'symbol': 'mtgoxSGD', 'low': null}, {'volume': 0, 'latest_trade': 1318789490, 'bid': null, 'high': null, 'currency': 'SGD', 'currency_volume': 0, 'ask': null, 'close': 5.200000000000, 'avg': null, 'symbol': 'ruxumSGD', 'low': null}, {'volume': 0, 'latest_trade': 1367946564, 'bid': 18050.000000000000, 'high': null, 'currency': 'SLL', 'currency_volume': 0, 'ask': 40000.000000000000, 'close': 30000.000000000000, 'avg': null, 'symbol': 'rockSLL', 'low': null}, {'volume': 697.290000000000, 'latest_trade': 1379617331, 'bid': 29425.000000000000, 'high': 30984.000000000000, 'currency': 'SLL', 'currency_volume': 21196785.940000000000, 'ask': 29977.000000000000, 'close': 29974.000000000000, 'avg': 30398.80959141820476415838460, 'symbol': 'virwoxSLL', 'low': 29441.000000000000}, {'volume': 7.111600000000, 'latest_trade': 1379581734, 'bid': 3669.340000000000, 'high': 3683.140000000000, 'currency': 'THB', 'currency_volume': 26193.018424000000, 'ask': 3865.700000000000, 'close': 3683.140000000000, 'avg': 3683.14, 'symbol': 'localbtcTHB', 'low': 3683.140000000000}, {'volume': 0, 'latest_trade': 1379403935, 'bid': 4234.218270000000, 'high': null, 'currency': 'THB', 'currency_volume': 0, 'ask': 4374.326630000000, 'close': 4469.878680000000, 'avg': null, 'symbol': 'mtgoxTHB', 'low': null}, {'volume': 0, 'latest_trade': 1318519297, 'bid': null, 'high': null, 'currency': 'THB', 'currency_volume': 0, 'ask': 345.000000000000, 'close': 135.000000000000, 'avg': null, 'symbol': 'ruxumTHB', 'low': null}, {'volume': 0, 'latest_trade': 1318793596, 'bid': null, 'high': null, 'currency': 'UAH', 'currency_volume': 0, 'ask': null, 'close': 30.000000000000, 'avg': null, 'symbol': 'ruxumUAH', 'low': null}, {'volume': 0, 'latest_trade': 1327176610, 'bid': null, 'high': null, 'currency': 'USD', 'currency_volume': 0, 'ask': null, 'close': 6.500000000000, 'avg': null, 'symbol': 'b2cUSD', 'low': null}, {'volume': 0, 'latest_trade': 1317843215, 'bid': null, 'high': null, 'currency': 'USD', 'currency_volume': 0, 'ask': null, 'close': 4.750000000000, 'avg': null, 'symbol': 'b7USD', 'low': null}, {'volume': 0, 'latest_trade': 1312592486, 'bid': null, 'high': null, 'currency': 'USD', 'currency_volume': 0, 'ask': null, 'close': 15.000000000000, 'avg': null, 'symbol': 'bcmBMUSD', 'low': null}, {'volume': 0, 'latest_trade': 1312408747, 'bid': null, 'high': null, 'currency': 'USD', 'currency_volume': 0, 'ask': null, 'close': 11.000000000000, 'avg': null, 'symbol': 'bcmLRUSD', 'low': null}, {'volume': 0, 'latest_trade': 1313715228, 'bid': null, 'high': null, 'currency': 'USD', 'currency_volume': 0, 'ask': null, 'close': 10.000000000000, 'avg': null, 'symbol': 'bcmMBUSD', 'low': null}, {'volume': 0, 'latest_trade': 1307246798, 'bid': null, 'high': null, 'currency': 'USD', 'currency_volume': 0, 'ask': null, 'close': 23.500000000000, 'avg': null, 'symbol': 'bcmPPUSD', 'low': null}, {'volume': 1.056200000000, 'latest_trade': 1379558204, 'bid': 125.100000000000, 'high': 139.000000000000, 'currency': 'USD', 'currency_volume': 145.811800000000, 'ask': 137.997000000000, 'close': 139.000000000000, 'avg': 138.0532096193902669948873319, 'symbol': 'bitboxUSD', 'low': 138.000000000000}, {'volume': 0, 'latest_trade': 1366236000, 'bid': null, 'high': null, 'currency': 'USD', 'currency_volume': 0, 'ask': null, 'close': 100.000000000000, 'avg': null, 'symbol': 'bitfloorUSD', 'low': null}, {'volume': 15.403376910000, 'latest_trade': 1379613388, 'bid': 129.000000000000, 'high': 136.500000000000, 'currency': 'USD', 'currency_volume': 2055.655000440000, 'ask': 134.000000000000, 'close': 134.000000000000, 'avg': 133.4548269805338419132405688, 'symbol': 'bitkonanUSD', 'low': 130.000000000000}, {'volume': 0, 'latest_trade': 1356047578, 'bid': null, 'high': null, 'currency': 'USD', 'currency_volume': 0, 'ask': null, 'close': 14.000000000000, 'avg': null, 'symbol': 'bitmarketUSD', 'low': null}, {'volume': 0, 'latest_trade': 1364508415, 'bid': null, 'high': null, 'currency': 'USD', 'currency_volume': 0, 'ask': null, 'close': 86.000000000000, 'avg': null, 'symbol': 'bitmeUSD', 'low': null}, {'volume': 14063.875775280000, 'latest_trade': 1379617133, 'bid': 124.330000000000, 'high': 128.000000000000, 'currency': 'USD', 'currency_volume': 1775587.557905633900, 'ask': 124.750000000000, 'close': 124.310000000000, 'avg': 126.2516525513240632478232525, 'symbol': 'bitstampUSD', 'low': 123.270000000000}, {'volume': 0, 'latest_trade': 1365846822, 'bid': null, 'high': null, 'currency': 'USD', 'currency_volume': 0, 'ask': null, 'close': 73.000000000000, 'avg': null, 'symbol': 'btc24USD', 'low': null}, {'volume': 4566.062965850000, 'latest_trade': 1379617341, 'bid': 122.529000000000, 'high': 126.010000000000, 'currency': 'USD', 'currency_volume': 566513.065605495170, 'ask': 122.541000000000, 'close': 122.616000000000, 'avg': 124.0703577332371205982150637, 'symbol': 'btceUSD', 'low': 120.200000000000}, {'volume': 0, 'latest_trade': 1342942225, 'bid': null, 'high': null, 'currency': 'USD', 'currency_volume': 0, 'ask': null, 'close': 6.801100000000, 'avg': null, 'symbol': 'btcexUSD', 'low': null}, {'volume': 0, 'latest_trade': 1305094318, 'bid': null, 'high': null, 'currency': 'USD', 'currency_volume': 0, 'ask': null, 'close': 5.100000000000, 'avg': null, 'symbol': 'btcexWMZ', 'low': null}, {'volume': 0, 'latest_trade': 1341981899, 'bid': null, 'high': null, 'currency': 'USD', 'currency_volume': 0, 'ask': null, 'close': 6.470000000000, 'avg': null, 'symbol': 'btctreeUSD', 'low': null}, {'volume': 993.124140730000, 'latest_trade': 1379616829, 'bid': 124.010000000000, 'high': 127.920000000000, 'currency': 'USD', 'currency_volume': 125336.201026991800, 'ask': 124.500000000000, 'close': 124.490000000000, 'avg': 126.2039617070056397520312848, 'symbol': 'cbxUSD', 'low': 123.750000000000}, {'volume': 0, 'latest_trade': 1353314729, 'bid': null, 'high': null, 'currency': 'USD', 'currency_volume': 0, 'ask': null, 'close': 13.350000000000, 'avg': null, 'symbol': 'cryptoxUSD', 'low': null}, {'volume': 39.055323640000, 'latest_trade': 1379612855, 'bid': 123.000000000000, 'high': 125.750000000000, 'currency': 'USD', 'currency_volume': 4846.854875393100, 'ask': 124.000000000000, 'close': 124.200000000000, 'avg': 124.1022842383773932029308361, 'symbol': 'crytrUSD', 'low': 123.000000000000}, {'volume': 0, 'latest_trade': 1318805936, 'bid': null, 'high': null, 'currency': 'USD', 'currency_volume': 0, 'ask': null, 'close': 3.639900000000, 'avg': null, 'symbol': 'exchbUSD', 'low': null}, {'volume': 30.000000000000, 'latest_trade': 1379611472, 'bid': 116.000000000000, 'high': 127.000000000000, 'currency': 'USD', 'currency_volume': 3790.000000000000, 'ask': 135.000000000000, 'close': 125.000000000000, 'avg': 126.3333333333333333333333333, 'symbol': 'fbtcUSD', 'low': 125.000000000000}, {'volume': 0, 'latest_trade': 1318013969, 'bid': null, 'high': null, 'currency': 'USD', 'currency_volume': 0, 'ask': null, 'close': 4.700000000000, 'avg': null, 'symbol': 'globalUSD', 'low': null}, {'volume': 0, 'latest_trade': 1378736174, 'bid': 115.000000000000, 'high': null, 'currency': 'USD', 'currency_volume': 0, 'ask': 139.000000000000, 'close': 149.990000000000, 'avg': null, 'symbol': 'icbitUSD', 'low': null}, {'volume': 0, 'latest_trade': 1350223254, 'bid': null, 'high': null, 'currency': 'USD', 'currency_volume': 0, 'ask': null, 'close': 19.999140620000, 'avg': null, 'symbol': 'imcexUSD', 'low': null}, {'volume': 0, 'latest_trade': 1350761253, 'bid': null, 'high': null, 'currency': 'USD', 'currency_volume': 0, 'ask': null, 'close': 11.900000000000, 'avg': null, 'symbol': 'intrsngUSD', 'low': null}, {'volume': 0, 'latest_trade': 1372956782, 'bid': 200.190000000000, 'high': null, 'currency': 'USD', 'currency_volume': 0, 'ask': 123.760000000000, 'close': 116.630000000000, 'avg': null, 'symbol': 'localbtcUSD', 'low': null}, {'volume': 0, 'latest_trade': 1370728226, 'bid': 101.010000000000, 'high': null, 'currency': 'USD', 'currency_volume': 0, 'ask': 139.999990000000, 'close': 119.000000000000, 'avg': null, 'symbol': 'lybitUSD', 'low': null}, {'volume': 19928.246802410000, 'latest_trade': 1379617318, 'bid': 134.875000000000, 'high': 142.000000000000, 'currency': 'USD', 'currency_volume': 2728585.825031242431, 'ask': 134.945600000000, 'close': 135.990000000000, 'avg': 136.9205154916720515858459940, 'symbol': 'mtgoxUSD', 'low': 131.140000000000}, {'volume': 0.106012000000, 'latest_trade': 1379569530, 'bid': 123.500000000000, 'high': 128.750000000000, 'currency': 'USD', 'currency_volume': 13.649045000000, 'ask': 128.750000000000, 'close': 128.750000000000, 'avg': 128.75, 'symbol': 'rippleUSD', 'low': 128.750000000000}, {'volume': 0, 'latest_trade': 1378765281, 'bid': 120.000000000000, 'high': null, 'currency': 'USD', 'currency_volume': 0, 'ask': 135.000000000000, 'close': 135.000000000000, 'avg': null, 'symbol': 'rockUSD', 'low': null}, {'volume': 0, 'latest_trade': 1347450254, 'bid': 50.000000000000, 'high': null, 'currency': 'USD', 'currency_volume': 0, 'ask': 15.000000000000, 'close': 14.750010000000, 'avg': null, 'symbol': 'ruxumUSD', 'low': null}, {'volume': 0, 'latest_trade': 1329154248, 'bid': null, 'high': null, 'currency': 'USD', 'currency_volume': 0, 'ask': null, 'close': 4.350275241100, 'avg': null, 'symbol': 'thLRUSD', 'low': null}, {'volume': 0, 'latest_trade': 1329172006, 'bid': null, 'high': null, 'currency': 'USD', 'currency_volume': 0, 'ask': null, 'close': 5.590000000000, 'avg': null, 'symbol': 'thUSD', 'low': null}, {'volume': 0, 'latest_trade': 1375796256, 'bid': 99.000000000000, 'high': null, 'currency': 'USD', 'currency_volume': 0, 'ask': 99.999999990000, 'close': 99.300000000000, 'avg': null, 'symbol': 'vcxUSD', 'low': null}, {'volume': 0, 'latest_trade': 1375088652, 'bid': 65.000000000000, 'high': null, 'currency': 'USD', 'currency_volume': 0, 'ask': 150.000000000000, 'close': 67.000000000000, 'avg': null, 'symbol': 'weexUSD', 'low': null}, {'volume': 0.190000000000, 'latest_trade': 1379529660, 'bid': 10300.000000000000, 'high': 11000.000000000000, 'currency': 'XRP', 'currency_volume': 2090.000000000000, 'ask': 13500.000000000000, 'close': 11000.000000000000, 'avg': 11000, 'symbol': 'justXRP', 'low': 11000.000000000000}, {'volume': 166.602622650000, 'latest_trade': 1379616420, 'bid': 11010.000000000000, 'high': 14400.000000000000, 'currency': 'XRP', 'currency_volume': 1978575.554151599164, 'ask': 11879.274431000000, 'close': 11995.000000000000, 'avg': 11876.01685183675086641860857, 'symbol': 'rippleXRP', 'low': 10849.117260000000}, {'volume': 0, 'latest_trade': 1367998202, 'bid': 7065.000000000000, 'high': null, 'currency': 'XRP', 'currency_volume': 0, 'ask': 8635.000000000000, 'close': 8999.000000000000, 'avg': null, 'symbol': 'snwcnXRP', 'low': null}, {'volume': 5.358700000000, 'latest_trade': 1379613881, 'bid': 1170.280000000000, 'high': 1277.850000000000, 'currency': 'ZAR', 'currency_volume': 6549.966639000000, 'ask': 1192.000000000000, 'close': 1239.790000000000, 'avg': 1222.305155914680799447627223, 'symbol': 'localbtcZAR', 'low': 1193.220000000000}, {'volume': 0, 'latest_trade': 1319028662, 'bid': null, 'high': null, 'currency': 'ZAR', 'currency_volume': 0, 'ask': 41.000000000000, 'close': 25.000000000000, 'avg': null, 'symbol': 'ruxumZAR', 'low': null}]";

            bool pullRemote = false; // BitCoinCharts says not to poll more than every 15 mins - this var holds the logic as to whether we need to pull or not

            if (LastDataPullTime == DateTime.MinValue) // if the last pull time is min value (aka first pull) then pull
                pullRemote = true;

            if (!pullRemote)  // if it's still false then check to see if it's been over 15 mins since we last pulled.
            {
                TimeSpan ts = DateTime.Now.Subtract(LastDataPullTime);
                if (ts.TotalMinutes >= 15)
                    pullRemote = true;
            }

            if (pullRemote)
            {
                string json = "";
                var request = WebRequest.Create(Properties.Settings.Default.MarketsAPIUrl);
                using (var resp = (HttpWebResponse)request.GetResponse())
                {
                    using (var reader = new StreamReader(resp.GetResponseStream()))
                    {
                        json = reader.ReadToEnd().Replace("\"", "'");
                    }
                }
                LastDataPullTime = DateTime.Now;
                LastMarketJsonString = json;
                return json;
            }
            else
            {
                // return the last string:
                return LastMarketJsonString;
            }
        }
        public static string GetResponseText(string url)
        {
            var request = WebRequest.Create(url);
            string returnValue = "";
            using (var resp = (HttpWebResponse)request.GetResponse())
            {
                using (var reader = new StreamReader(resp.GetResponseStream()))
                {
                    returnValue = reader.ReadToEnd();
                }
            }
            return returnValue;
        }
        #endregion

        #region Extensions
        public static decimal RemoveEndZeroes(this decimal input)
        {
            string val = input.ToString();
            int stopIndex = 0;

            for (int i = val.Length - 1; i >= 0; i--)
            {
                if (val[i] != '0')
                {
                    stopIndex = i + 1;
                    break;
                }
            }

            if (stopIndex > 0)
            {
                val = val.Substring(0, stopIndex);
            }

            if (val.EndsWith("."))
                val = val.Substring(0, val.Length - 1);

            return decimal.Parse(val);
        }
        #endregion
    }
}
